package com.wyc.controller;

import com.wyc.pojo.AllAnnMg;
import com.wyc.pojo.SuperAdminAnnMg;
import com.wyc.service.AllAnnMgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AllAnnMgController
 * @Author 王韫琛
 * @Date 2021/1/28 3:20
 * @Version 1.0
 */
@Controller
public class AllAnnMgController {
    @Autowired
    private AllAnnMgService allAnnMgService;
    //跳转到用户公告展示界面
    @RequestMapping("/userViewAnnouncements")
    public String userViewAnnouncements(){
        return "/view/user_jsp/userViewAnnouncements";
    }
    //超级管理员查询公告信息分页显示
    @ResponseBody
    @RequestMapping("/userAdminFindPage")
    public String userAdminFindPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize
    ){
        Map<String,Object> map = new HashMap<>();
        //调用service得到分页对象
        List<AllAnnMg> pageInfo = allAnnMgService.findPage(pageNum,pageSize);
        map.put("code",0);
        map.put("msg","");
        map.put("count",allAnnMgService.getTotal());
        map.put("data",pageInfo);//数据列表
        return cn.hutool.json.JSONUtil.toJsonStr(map);
    }
    //普通用户按照身份搜索公告
    @RequestMapping("/findAllAnnMgByType")
    @ResponseBody
    public String findAllAnnMgByType( String permission,@RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize){
        System.out.println(permission);
        System.out.println(allAnnMgService.getTypeTotal(permission));
        Map<String,Object> map = new HashMap<>();
        List<AllAnnMg> pageInfo = allAnnMgService.findAllAnnMgByType(permission,pageNum,pageSize);
        map.put("code",0);
        map.put("msg","");
        map.put("count",allAnnMgService.getTypeTotal(permission));
        map.put("data",pageInfo);//数据列表
        return cn.hutool.json.JSONUtil.toJsonStr(map);
    }
}
